package cn.buk.tms.entity.misc;

import cn.buk.tms.entity.base.BaseInfo;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.util.Date;
import jakarta.persistence.*;

/**
 * 客户：企业客户、散客、同行等从我处购买产品或服务的个人或企业。
 *
 * @author yfdai
 */
@Entity
@Table(name = "t102", uniqueConstraints = @UniqueConstraint(name = "uk_customer_enterprise",
        columnNames = {"enterprise_id", "customer_enterprise_id"}))
public class Customer extends BaseInfo {

  /**
   * 企业散客
   * （散客）企业
   */
  public static final int ENT_INDIVIDUAL = 0;

  /**
   * 月结企业客户
   */
  public static final int ENT_CORPORATION = 1;

  /**
   * 该客户对应的enterpriseId,
   * 可以为null, 但不允许为0
   */
  @Column(name = "customer_enterprise_id")
  private Integer customerEnterpriseId;

  /**
   * 企业名称
   */
  @Column(length = 50)
  private String vipName;

  /**
   * 企业全称
   */
  @Column(length = 50)
  private String fullName;

  /**
   * 客户编号(用户自定义，用于显示）
   */
  @Column(name = "customer_code", length = 30)
  private String customerCode;

  /**
   * 拼音，用于排序
   */
  @Column(length = 10)
  private String pinyin;

  /**
   * 企业类型：
   * 1/NULL - 企业客户
   * 0 - 散客企业（个体户？）
   */
  @Column(name = "enterprise_type")
  private Integer enterpriseType;

  /**
   * 服务项目
   */
  @Column(name = "service_item")
  private String serviceItem;

  /**
   * 销售员
   */
  @Column(name = "sales_staff")
  private String salesStaff;

  /**
   * 客户维护人
   */
  @Column(name = "customer_maintainer")
  private String customerMaintainer;

  /**
   * 结算方式类型
   * 0 - 不知道
   * 1 - 次日结算
   * 2 - 周结
   * 3 - 月结
   */
  @Column(name = "settlement_type")
  private Integer settlementType;

  /**
   * 结算方式备注
   */
  @Column(name = "settlement_mode")
  private String settlementMode;

  /**
   * 结算周期
   */
  @Column(name = "settlement_period")
  private String settlementPeriod;

  /**
   * 协议开始日期
   */
  @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  @Column(name = "begin_date")
  private Date agreementBeginDate;

  /**
   * 协议结束日期
   */
  @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  @Column(name = "end_date")
  private Date agreementEndDate;

  /**
   * 与t101中的username相同, 冗余
   */
  private String username;

  /**
   * 合同联系人
   */
  @Column(name = "contract_linkman")
  private String contractLinkman;

  /**
   * 合同联系人的联系电话
   */
  @Column(name = "contract_link_phone")
  private String contractLinkPhone;

  /**
   * 企业差旅负责人（审核人）(账单）
   */
  @Column(length = 30)
  private String linkman;

  /**
   * 联系电话
   */
  @Column(length = 20)
  private String phone;

  private String email;

  private String mobile;

  @Column(length = 20)
  private String fax;

  /**
   * 邮编
   */
  @Column(name = "post_code")
  private String postCode;

  /**
   * 账单邮寄地址
   */
  @Column(name = "vipaddr", length = 200)
  private String address;


  /**
   * 备注
   */
  @Column(length = 50)
  private String remark;

  /**
   * 是否需要审批出票
   * 0/null-不需要
   * 1-需要
   */
  @Column(name = "approval_ticket")
  private Integer approvalTicket;

  /**
   * 审核方式类型
   * 1-手机/电话通知
   * 2-短信
   * 3-邮件
   * 4-微信
   */
  @Column(name = "approval_type")
  private Integer approvalType;

  /**
   * 审核方式备注
   */
  @Column(name = "approval_mode")
  private String approvalMode;

  /**
   * 行程单需求类型
   * 0 - 不需要
   * 1 - 行程单
   * 2 - 发票
   * 3 - 信息单
   */
  @Column(name = "itinerary_type")
  private Integer itineraryType;

  /**
   * @deprecated 该字段暂时废弃，目前短信中不再使用短网址
   * 是否启用短网址
   * null/0 - 不启用
   * 1 - 启用
   */
  @Deprecated(since = "2021-10-24", forRemoval = true)
  @Column(name = "short_url")
  private Integer shortUrl;

  /**
   * 短信发送模式
   * 0-不自动发送短信（机票订单回填票号成功，不自动发送短信）
   * 1/null - 自动发送短信（机票订单回填票号成功，不自动发送短信）
   */
  @Column(name = "sms_mode")
  private Integer smsMode;

  /**
   * 客户服务分组，对应GroupCustomerService.groupCode
   *
   * @see GroupCustomerService
   */
  @Column(name = "group_code", length = 5)
  private String customerServiceGroupCode;

  /**
   * 临时代码
   * 修改Customer时，输入的参数用的是实体类Customer.java，无法做转换
   */
  @Transient
  private String groupCode;

  /**
   * 适用的服务费模板
   */
  @Column(name = "template_code", length = 5)
  private String templateCode;

  /**
   * 结算单报表模板ID
   */
  @Column(name = "report_tpl_Id")
  private Integer reportTemplateId;

  /**
   * 客户合作状态：
   * null/1 - 启用
   * 0 - 停用
   */
  private Integer status = 1;

  /**
   * 是否处于测试模式，测试模式的客户所有的订单全部人工处理
   * 0/null: 不是测试模式
   * 1: 是测试模式
   */
  @Column(name = "test_mode")
  private Integer testMode;

  /**
   * 最近一次消费
   */
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  @Temporal(TemporalType.TIMESTAMP)
  private Date recency;



  /**
   * @return the vipName
   */
  public String getVipName() {
    return vipName;
  }

  /**
   * @param vipName the vipName to set
   */
  public void setVipName(String vipName) {
    this.vipName = vipName;
  }

  /**
   * @return the fullName
   */
  public String getFullName() {
    return fullName;
  }

  /**
   * @param fullName the fullName to set
   */
  public void setFullName(String fullName) {
    this.fullName = fullName;
  }

  /**
   * @return the address
   */
  public String getAddress() {
    return address;
  }

  /**
   * @param address the address to set
   */
  public void setAddress(String address) {
    this.address = address;
  }

  /**
   * @return the phone
   */
  public String getPhone() {
    return phone;
  }

  /**
   * @param phone the phone to set
   */
  public void setPhone(String phone) {
    this.phone = phone;
  }

  /**
   * @return the fax
   */
  public String getFax() {
    return fax;
  }

  /**
   * @param fax the fax to set
   */
  public void setFax(String fax) {
    this.fax = fax;
  }

  /**
   * @return the remark
   */
  public String getRemark() {
    return remark;
  }

  /**
   * @param remark the remark to set
   */
  public void setRemark(String remark) {
    this.remark = remark;
  }

  public int getApprovalTicket() {
    return approvalTicket == null ? 0 : approvalTicket;
  }

  public void setApprovalTicket(Integer approvalTicket) {
    this.approvalTicket = approvalTicket;
  }

  public String getPostCode() {
    return postCode;
  }

  public void setPostCode(String postCode) {
    this.postCode = postCode;
  }

  public String getMobile() {
    return mobile;
  }

  public void setMobile(String mobile) {
    this.mobile = mobile;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getCustomerCode() {
    return customerCode;
  }

  public void setCustomerCode(String customerCode) {
    this.customerCode = customerCode == null ? null : customerCode.trim();
  }

  public String getServiceItem() {
    return serviceItem;
  }

  public void setServiceItem(String serviceItem) {
    this.serviceItem = serviceItem;
  }

  public String getSalesStaff() {
    return salesStaff == null ? "" : salesStaff.trim();
  }

  public void setSalesStaff(String salesStaff) {
    this.salesStaff = salesStaff;
  }

  public String getCustomerMaintainer() {
    return customerMaintainer;
  }

  public void setCustomerMaintainer(String customerMaintainer) {
    this.customerMaintainer = customerMaintainer;
  }

  public String getSettlementMode() {
    return settlementMode;
  }

  public void setSettlementMode(String settlementMode) {
    this.settlementMode = settlementMode;
  }

  public Date getAgreementBeginDate() {
    return agreementBeginDate;
  }

  public void setAgreementBeginDate(Date agreementBeginDate) {
    this.agreementBeginDate = agreementBeginDate;
  }

  public Date getAgreementEndDate() {
    return agreementEndDate;
  }

  public void setAgreementEndDate(Date agreementEndDate) {
    this.agreementEndDate = agreementEndDate;
  }

  public String getContractLinkman() {
    return contractLinkman;
  }

  public void setContractLinkman(String contractLinkman) {
    this.contractLinkman = contractLinkman;
  }

  public String getContractLinkPhone() {
    return contractLinkPhone;
  }

  public void setContractLinkPhone(String contractLinkPhone) {
    this.contractLinkPhone = contractLinkPhone;
  }

  public String getLinkman() {
    return linkman;
  }

  public void setLinkman(String linkman) {
    this.linkman = linkman;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getSettlementPeriod() {
    return settlementPeriod;
  }

  public void setSettlementPeriod(String settlementPeriod) {
    this.settlementPeriod = settlementPeriod;
  }

  public String getApprovalMode() {
    return approvalMode;
  }

  public void setApprovalMode(String approvalMode) {
    this.approvalMode = approvalMode;
  }


  public int getSettlementType() {
    return settlementType == null ? 0 : settlementType;
  }

  public void setSettlementType(Integer settlementType) {
    this.settlementType = settlementType;
  }

  public int getApprovalType() {
    return approvalType == null ? 0 : approvalType;
  }

  public void setApprovalType(Integer approvalType) {
    this.approvalType = approvalType;
  }

  public int getItineraryType() {
    return itineraryType == null ? 0 : itineraryType;
  }

  public void setItineraryType(Integer itineraryType) {
    this.itineraryType = itineraryType;
  }

  public String getPinyin() {
    return pinyin;
  }

  public void setPinyin(String pinyin) {
    if (pinyin != null) {
      pinyin = pinyin.trim().toUpperCase();
    }
    this.pinyin = pinyin;
  }

  public int getEnterpriseType() {
    return enterpriseType == null ? ENT_CORPORATION : enterpriseType;
  }

  public void setEnterpriseType(int enterpriseType) {
    this.enterpriseType = enterpriseType;
  }

  public int getCustomerEnterpriseId() {
    return customerEnterpriseId == null ? 0 : customerEnterpriseId;
  }

  public void setCustomerEnterpriseId(Integer customerEnterpriseId) {
    if (customerEnterpriseId != null && customerEnterpriseId != 0) {
      this.customerEnterpriseId = customerEnterpriseId;
    }
  }

  public int getStatus() {
    return status == null ? 1 : status;
  }

  public void setStatus(Integer status) {
    this.status = status;
  }

  public int getShortUrl() {
    return shortUrl == null ? 0 : shortUrl;
  }

  public void setShortUrl(Integer shortUrl) {
    this.shortUrl = shortUrl;
  }

  public Date getRecency() {
    return recency;
  }

  public void setRecency(Date recency) {
    this.recency = recency;
  }

  public String getCustomerServiceGroupCode() {
    return customerServiceGroupCode;
  }

  public void setCustomerServiceGroupCode(String customerServiceGroupCode) {
    this.customerServiceGroupCode = customerServiceGroupCode;
  }

  public String getGroupCode() {
    return groupCode;
  }

  public void setGroupCode(String groupCode) {
    this.groupCode = groupCode;
  }

  public int getSmsMode() {
    return smsMode == null ? 1 : smsMode;
  }

  public void setSmsMode(Integer smsMode) {
    this.smsMode = smsMode;
  }

  public String getTemplateCode() {
    return templateCode;
  }

  public void setTemplateCode(String templateCode) {
    this.templateCode = templateCode;
  }

  public int getReportTemplateId() {
    return reportTemplateId == null ? 1 : reportTemplateId;
  }

  public void setReportTemplateId(Integer reportTemplateId) {
    this.reportTemplateId = reportTemplateId;
  }

  public int getTestMode() {
    return testMode == null ? 0 : testMode;
  }

  public void setTestMode(Integer testMode) {
    this.testMode = testMode;
  }
}